package com.egu.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.egu.model.CustomerCondition;
import com.egu.service.CustomerConditionService;
import com.egu.vo.PageParam;
import com.egu.vo.RequestPageVo;
import com.egu.vo.RequestResultVo;

@Controller
@RequestMapping("customerCondition")
public class CustomerConditionController {

	@Autowired
	private CustomerConditionService customerConditionService;

	@RequestMapping("listUI")
	public String listUI() {
		return "customerCondition/listUI";
	}

	// rder = "asc" offset = 0 limit = 10;
	@RequestMapping("/getList")
	@ResponseBody
	public RequestPageVo<CustomerCondition> getList(@ModelAttribute(value = "param") PageParam param, CustomerCondition customerCondition) {
		RequestPageVo<CustomerCondition> vo = customerConditionService.getList(param, customerCondition);
		return vo;
	}

	
	@RequestMapping("/getAllList")
	@ResponseBody
	public RequestResultVo<List<CustomerCondition>> getList() {
		RequestResultVo<List<CustomerCondition>> vo = customerConditionService.getAllList();
		return vo;
	}

	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public RequestResultVo<CustomerCondition> saveOrUpdate(CustomerCondition customerCondition) {
		RequestResultVo<CustomerCondition> result = new RequestResultVo<CustomerCondition>();
		if (customerCondition != null) {
			return customerConditionService.saveOrUpdate(customerCondition);
		} else {
			result.setSuccess(false);
		}
		return result;
	}
	
	@RequestMapping("/deleteDataById")
	public @ResponseBody RequestResultVo<CustomerCondition> deleteDataById(
			@RequestParam(value = "id", required = false) Integer id) {
		RequestResultVo<CustomerCondition> result = new RequestResultVo<CustomerCondition>();
		if (id == null) {
			result.setSuccess(false);
			result.setErrorMessage("传入id为空");
			return result;
		}
		result = customerConditionService.deleteDataById(id);
		return result;
	}
}
